home *** CD-ROM | disk | FTP | other *** search
- /* ScoreEffectWindow.c */
- /*****************************************************************************/
- /* */
- /* Out Of Phase: Digital Music Synthesis on General Purpose Computers */
- /* Copyright (C) 1994 Thomas R. Lawrence */
- /* */
- /* This program is free software; you can redistribute it and/or modify */
- /* it under the terms of the GNU General Public License as published by */
- /* the Free Software Foundation; either version 2 of the License, or */
- /* (at your option) any later version. */
- /* */
- /* This program is distributed in the hope that it will be useful, */
- /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
- /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
- /* GNU General Public License for more details. */
- /* */
- /* You should have received a copy of the GNU General Public License */
- /* along with this program; if not, write to the Free Software */
- /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
- /* */
- /* Thomas R. Lawrence can be reached at tomlaw@world.std.com. */
- /* */
- /*****************************************************************************/
-
- #include "MiscInfo.h"
- #include "Audit.h"
- #include "Debug.h"
- #include "Definitions.h"
-
- #include "ScoreEffectWindow.h"
- #include "MainWindowStuff.h"
- #include "WindowDispatcher.h"
- #include "TextEdit.h"
- #include "Memory.h"
- #include "GlobalWindowMenuList.h"
- #include "Main.h"
- #include "GrowIcon.h"
- #include "FindDialog.h"
- #include "DataMunging.h"
- #include "EffectSpecList.h"
-
-
- #define WINDOWLEFT (15)
- #define WINDOWTOP (30)
- #define WINDOWWIDTH (480)
- #define WINDOWHEIGHT (250)
-
-
- struct ScoreEffectWindowRec
- {
- MainWindowRec* MainWindow;
- WinType* ScreenID;
- GenericWindowRec* MyGenericWindow; /* how the window event dispatcher knows us */
- MenuItemType* MyMenuItem;
- TextEditRec* Editor;
- };
-
-
- /* create a new score effect window. */
- ScoreEffectWindowRec* NewScoreEffectWindow(struct MainWindowRec* MainWindow,
- char* Text)
- {
- ScoreEffectWindowRec* Window;
-
- CheckPtrExistence(MainWindow);
-
- Window = (ScoreEffectWindowRec*)AllocPtrCanFail(sizeof(ScoreEffectWindowRec),
- "ScoreEffectWindowRec");
- if (Window == NIL)
- {
- FailurePoint1:
- return NIL;
- }
-
- Window->MainWindow = MainWindow;
-
- Window->ScreenID = MakeNewWindow(eDocumentWindow,eWindowClosable,
- eWindowZoomable,eWindowResizable,WINDOWLEFT,WINDOWTOP,WINDOWWIDTH,WINDOWHEIGHT,
- (void (*)(void*))&ScoreEffectWindowUpdator,Window);
- if (Window->ScreenID == 0)
- {
- FailurePoint2:
- ReleasePtr((char*)Window);
- goto FailurePoint1;
- }
-
- Window->Editor = NewTextEdit(Window->ScreenID,
- (TEScrollType)(eTEVScrollBar | eTEHScrollBar),GetMonospacedFont(),9,
- -1,-1,GetWindowWidth(Window->ScreenID) + 2,GetWindowHeight(Window->ScreenID) + 2);
- if (Window->Editor == NIL)
- {
- FailurePoint3:
- KillWindow(Window->ScreenID);
- goto FailurePoint2;
- }
-
- Window->MyGenericWindow = CheckInNewWindow(Window->ScreenID,Window,
- (void (*)(void*,MyBoolean,OrdType,OrdType,ModifierFlags))&ScoreEffectWindowDoIdle,
- (void (*)(void*))&ScoreEffectWindowBecomeActive,
- (void (*)(void*))&ScoreEffectWindowBecomeInactive,
- (void (*)(void*))&ScoreEffectWindowJustResized,
- (void (*)(OrdType,OrdType,ModifierFlags,void*))&ScoreEffectWindowDoMouseDown,
- (void (*)(unsigned char,ModifierFlags,void*))&ScoreEffectWindowDoKeyDown,
- (void (*)(void*))&ScoreEffectWindowClose,
- (void (*)(void*))&ScoreEffectWindowMenuSetup,
- (void (*)(void*,MenuItemType*))&ScoreEffectWindowDoMenuCommand);
- if (Window->MyGenericWindow == NIL)
- {
- FailurePoint4:
- DisposeTextEdit(Window->Editor);
- goto FailurePoint3;
- }
-
- Window->MyMenuItem = MakeNewMenuItem(mmWindowMenu,"x",0);
- if (Window->MyMenuItem == NIL)
- {
- FailurePoint5:
- CheckOutDyingWindow(Window->MyGenericWindow);
- goto FailurePoint4;
- }
-
- if (!RegisterWindowMenuItem(Window->MyMenuItem,(void (*)(void*))&ActivateThisWindow,
- Window->ScreenID))
- {
- FailurePoint6:
- KillMenuItem(Window->MyMenuItem);
- goto FailurePoint5;
- }
-
- SetTextEditAutoIndent(Window->Editor,True);
- SetTextEditTabSize(Window->Editor,MainWindowGetTabSize(MainWindow));
-
- TextEditNewRawData(Window->Editor,Text,"\x0a");
- TextEditHasBeenSaved(Window->Editor);
-
- ScoreEffectWindowResetTitlebar(Window);
-
- return Window;
- }
-
-
- /* dispose of a score effect window. */
- void DisposeScoreEffectWindow(ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
-
- /* save data */
- if (!ScoreEffectWindowWritebackModifiedData(Window))
- {
- /* failed -- now what? */
- }
-
- MainWindowNotifyScoreEffectWindowClosed(Window->MainWindow,Window);
- DeregisterWindowMenuItem(Window->MyMenuItem);
- KillMenuItem(Window->MyMenuItem);
- CheckOutDyingWindow(Window->MyGenericWindow);
- DisposeTextEdit(Window->Editor);
- KillWindow(Window->ScreenID);
- ReleasePtr((char*)Window);
- }
-
-
- void ScoreEffectWindowDoIdle(ScoreEffectWindowRec* Window,
- MyBoolean CheckCursorFlag, OrdType XLoc, OrdType YLoc,
- ModifierFlags Modifiers)
- {
- CheckPtrExistence(Window);
- TextEditUpdateCursor(Window->Editor);
- if (CheckCursorFlag)
- {
- if (TextEditIBeamTest(Window->Editor,XLoc,YLoc))
- {
- SetIBeamCursor();
- }
- else
- {
- SetArrowCursor();
- }
- }
- }
-
-
- void ScoreEffectWindowBecomeActive(ScoreEffectWindowRec* Window)
- {
- OrdType XSize;
- OrdType YSize;
-
- CheckPtrExistence(Window);
- EnableTextEditSelection(Window->Editor);
- XSize = GetWindowWidth(Window->ScreenID);
- YSize = GetWindowHeight(Window->ScreenID);
- SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
- DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(True/*enablegrowicon*/));
- }
-
-
- void ScoreEffectWindowBecomeInactive(ScoreEffectWindowRec* Window)
- {
- OrdType XSize;
- OrdType YSize;
-
- CheckPtrExistence(Window);
- DisableTextEditSelection(Window->Editor);
- XSize = GetWindowWidth(Window->ScreenID);
- YSize = GetWindowHeight(Window->ScreenID);
- SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
- DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(False/*disablegrowicon*/));
- }
-
-
- void ScoreEffectWindowJustResized(ScoreEffectWindowRec* Window)
- {
- OrdType XSize;
- OrdType YSize;
-
- CheckPtrExistence(Window);
- XSize = GetWindowWidth(Window->ScreenID);
- YSize = GetWindowHeight(Window->ScreenID);
- SetClipRect(Window->ScreenID,0,0,XSize,YSize);
- DrawBoxErase(Window->ScreenID,0,0,XSize,YSize);
- SetTextEditPosition(Window->Editor,-1,-1,XSize + 2,YSize + 2);
- }
-
-
- void ScoreEffectWindowDoMouseDown(OrdType XLoc, OrdType YLoc,
- ModifierFlags Modifiers, ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
- if ((XLoc >= GetWindowWidth(Window->ScreenID) - 15)
- && (XLoc < GetWindowWidth(Window->ScreenID))
- && (YLoc >= GetWindowHeight(Window->ScreenID) - 15)
- && (YLoc < GetWindowHeight(Window->ScreenID)))
- {
- UserGrowWindow(Window->ScreenID,XLoc,YLoc);
- ScoreEffectWindowJustResized(Window);
- }
- else if (TextEditHitTest(Window->Editor,XLoc,YLoc))
- {
- TextEditDoMouseDown(Window->Editor,XLoc,YLoc,Modifiers);
- }
- }
-
-
- void ScoreEffectWindowDoKeyDown(unsigned char KeyCode,
- ModifierFlags Modifiers, ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
- TextEditDoKeyPressed(Window->Editor,KeyCode,Modifiers);
- }
-
-
- void ScoreEffectWindowClose(ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
- DisposeScoreEffectWindow(Window);
- }
-
-
- void ScoreEffectWindowUpdator(ScoreEffectWindowRec* Window)
- {
- OrdType XSize;
- OrdType YSize;
-
- CheckPtrExistence(Window);
- TextEditFullRedraw(Window->Editor);
- XSize = GetWindowWidth(Window->ScreenID);
- YSize = GetWindowHeight(Window->ScreenID);
- SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
- DrawBitmap(Window->ScreenID,XSize-15,YSize-15,
- GetGrowIcon(Window->MyGenericWindow == GetCurrentWindowID()));
- }
-
-
- void ScoreEffectWindowMenuSetup(ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
- MainWindowEnableGlobalMenus(Window->MainWindow);
- EnableMenuItem(mPaste);
- ChangeItemName(mPaste,"Paste Text");
- if (TextEditIsThereValidSelection(Window->Editor))
- {
- EnableMenuItem(mCut);
- ChangeItemName(mCut,"Cut Text");
- EnableMenuItem(mCopy);
- ChangeItemName(mCopy,"Copy Text");
- EnableMenuItem(mClear);
- ChangeItemName(mClear,"Clear Text");
- }
- EnableMenuItem(mShiftLeft);
- EnableMenuItem(mShiftRight);
- EnableMenuItem(mBalanceParens);
- EnableMenuItem(mSelectAll);
- ChangeItemName(mSelectAll,"Select All Text");
- if (TextEditCanWeUndo(Window->Editor))
- {
- EnableMenuItem(mUndo);
- ChangeItemName(mUndo,"Undo Text Change");
- }
- ChangeItemName(mCloseFile,"Close Score Effects");
- EnableMenuItem(mCloseFile);
- EnableMenuItem(mFind);
- if (PtrSize(GlobalSearchString) != 0)
- {
- EnableMenuItem(mFindAgain);
- if (TextEditIsThereValidSelection(Window->Editor))
- {
- EnableMenuItem(mReplace);
- EnableMenuItem(mReplaceAndFindAgain);
- }
- }
- EnableMenuItem(mShowSelection);
- if (TextEditIsThereValidSelection(Window->Editor))
- {
- EnableMenuItem(mEnterSelection);
- }
- SetItemCheckmark(Window->MyMenuItem);
- ChangeItemName(mBuildFunction,"Compile Score Effects");
- EnableMenuItem(mBuildFunction);
- }
-
-
- void ScoreEffectWindowDoMenuCommand(ScoreEffectWindowRec* Window,
- MenuItemType* MenuItem)
- {
- CheckPtrExistence(Window);
- if (MainWindowDoGlobalMenuItem(Window->MainWindow,MenuItem))
- {
- }
- else if (MenuItem == mPaste)
- {
- TextEditDoMenuPaste(Window->Editor);
- }
- else if (MenuItem == mCut)
- {
- TextEditDoMenuCut(Window->Editor);
- }
- else if (MenuItem == mCopy)
- {
- TextEditDoMenuCopy(Window->Editor);
- }
- else if (MenuItem == mClear)
- {
- TextEditDoMenuClear(Window->Editor);
- }
- else if (MenuItem == mSelectAll)
- {
- TextEditDoMenuSelectAll(Window->Editor);
- }
- else if (MenuItem == mUndo)
- {
- TextEditDoMenuUndo(Window->Editor);
- }
- else if (MenuItem == mCloseFile)
- {
- ScoreEffectWindowClose(Window);
- }
- else if (MenuItem == mShiftLeft)
- {
- TextEditShiftSelectionLeftOneTab(Window->Editor);
- }
- else if (MenuItem == mShiftRight)
- {
- TextEditShiftSelectionRightOneTab(Window->Editor);
- }
- else if (MenuItem == mBalanceParens)
- {
- TextEditBalanceParens(Window->Editor);
- }
- else if (MenuItem == mFind)
- {
- switch (DoFindDialog(&GlobalSearchString,&GlobalReplaceString,
- mCut,mPaste,mCopy,mUndo,mSelectAll,mClear))
- {
- default:
- EXECUTE(PRERR(ForceAbort,
- "ScoreEffectWindowDoMenuCommand: bad value from DoFindDialog"));
- break;
- case eFindCancel:
- case eDontFind:
- break;
- case eFindFromStart:
- SetTextEditInsertionPoint(Window->Editor,0,0);
- TextEditFindAgain(Window->Editor,GlobalSearchString);
- TextEditShowSelection(Window->Editor);
- break;
- case eFindAgain:
- TextEditFindAgain(Window->Editor,GlobalSearchString);
- TextEditShowSelection(Window->Editor);
- break;
- }
- }
- else if (MenuItem == mFindAgain)
- {
- TextEditFindAgain(Window->Editor,GlobalSearchString);
- TextEditShowSelection(Window->Editor);
- }
- else if (MenuItem == mReplace)
- {
- if (TextEditIsThereValidSelection(Window->Editor))
- {
- TextEditInsertRawDataWithUndo(Window->Editor,GlobalReplaceString,
- SYSTEMLINEFEED);
- }
- }
- else if (MenuItem == mReplaceAndFindAgain)
- {
- if (TextEditIsThereValidSelection(Window->Editor))
- {
- TextEditInsertRawDataWithUndo(Window->Editor,GlobalReplaceString,
- SYSTEMLINEFEED);
- TextEditFindAgain(Window->Editor,GlobalSearchString);
- TextEditShowSelection(Window->Editor);
- }
- }
- else if (MenuItem == mShowSelection)
- {
- TextEditShowSelection(Window->Editor);
- }
- else if (MenuItem == mEnterSelection)
- {
- char* NewString;
-
- NewString = TextEditGetSelection(Window->Editor);
- if (NewString != NIL)
- {
- ReleasePtr(GlobalSearchString);
- GlobalSearchString = NewString;
- }
- }
- else if (MenuItem == mBuildFunction)
- {
- EffectSpecListRec* EffectSpec;
-
- EffectSpec = MainWindowGetScoreEffectsSpec(Window->MainWindow);
- if (EffectSpec != NIL)
- {
- DisposeEffectSpecList(EffectSpec);
- }
- }
- else
- {
- EXECUTE(PRERR(AllowResume,"ScoreEffectWindowDoMenuCommand: unknown menu command"));
- }
- }
-
-
- /* get the string from the editor */
- char* ScoreEffectWindowGetText(ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
- return TextEditGetRawData(Window->Editor,"\x0a");
- }
-
-
- /* make editor window come to top */
- void ScoreEffectWindowBringToTop(ScoreEffectWindowRec* Window)
- {
- CheckPtrExistence(Window);
- ActivateThisWindow(Window->ScreenID);
- }
-
-
- /* utility routine to hilite a text line on which a compile error has occurred */
- void ScoreEffectWindowHiliteLine(ScoreEffectWindowRec* Window,
- long ErrorLine)
- {
- CheckPtrExistence(Window);
- SetTextEditSelection(Window->Editor,ErrorLine,0,ErrorLine + 1,0);
- TextEditShowSelection(Window->Editor);
- }
-
-
- /* the name of the document has changed, so change the name of the window */
- void ScoreEffectWindowGlobalNameChange(ScoreEffectWindowRec* Window,
- char* NewFilename)
- {
- char* SeparatorString;
-
- CheckPtrExistence(Window);
- CheckPtrExistence(NewFilename);
-
- SeparatorString = StringToBlockCopy(": Score Effects");
- if (SeparatorString != NIL)
- {
- char* TotalString;
-
- TotalString = ConcatBlockCopy(NewFilename,SeparatorString);
- if (TotalString != NIL)
- {
- char* NullTerminatedString;
-
- NullTerminatedString = BlockToStringCopy(TotalString);
- if (NullTerminatedString != NIL)
- {
- SetWindowName(Window->ScreenID,NullTerminatedString);
- ChangeItemName(Window->MyMenuItem,NullTerminatedString);
- ReleasePtr(NullTerminatedString);
- }
- ReleasePtr(TotalString);
- }
- ReleasePtr(SeparatorString);
- }
- }
-
-
- /* refresh the titlebar of the window */
- void ScoreEffectWindowResetTitlebar(ScoreEffectWindowRec* Window)
- {
- char* DocumentName;
-
- CheckPtrExistence(Window);
- DocumentName = GetCopyOfDocumentName(Window->MainWindow);
- if (DocumentName != NIL)
- {
- ScoreEffectWindowGlobalNameChange(Window,DocumentName);
- ReleasePtr(DocumentName);
- }
- }
-
-
- /* force the window to write back to the object any data that has changed */
- MyBoolean ScoreEffectWindowWritebackModifiedData(ScoreEffectWindowRec* Window)
- {
- MyBoolean SuccessFlag = True;
-
- CheckPtrExistence(Window);
-
- if (TextEditDoesItNeedToBeSaved(Window->Editor))
- {
- char* String;
-
- String = ScoreEffectWindowGetText(Window);
- if (String != NIL)
- {
- PutMainWindowScoreEffects(Window->MainWindow,String);
- TextEditHasBeenSaved(Window->Editor);
- }
- else
- {
- SuccessFlag = False;
- }
- }
-
- return SuccessFlag;
- }
-